package com.example.HQCource;

import com.HQCourse.vod.vod.service.ChapterService;
import com.HQCourse.vod.vod.service.VideoService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.HQCourse.model.vod.Chapter;
import com.example.HQCourse.model.vod.Video;
import com.example.HQCourse.vo.vod.ChapterVo;
import com.example.HQCourse.vo.vod.VideoVo;
import org.junit.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public class Demo {
    @Autowired
    private ChapterService chapterService;
    @Autowired
    private VideoService videoService;
    @Test
    public void test() {
        BaseMapper<Chapter> baseMapper=new BaseMapper<Chapter>() {
            @Override
            public int insert(Chapter entity) {
                return 0;
            }

            @Override
            public int deleteById(Serializable id) {
                return 0;
            }

            @Override
            public int deleteByMap(Map<String, Object> columnMap) {
                return 0;
            }

            @Override
            public int delete(Wrapper<Chapter> wrapper) {
                return 0;
            }

            @Override
            public int deleteBatchIds(Collection<? extends Serializable> idList) {
                return 0;
            }

            @Override
            public int updateById(Chapter entity) {
                return 0;
            }

            @Override
            public int update(Chapter entity, Wrapper<Chapter> updateWrapper) {
                return 0;
            }

            @Override
            public Chapter selectById(Serializable id) {
                return null;
            }

            @Override
            public List<Chapter> selectBatchIds(Collection<? extends Serializable> idList) {
                return null;
            }

            @Override
            public List<Chapter> selectByMap(Map<String, Object> columnMap) {
                return null;
            }

            @Override
            public Chapter selectOne(Wrapper<Chapter> queryWrapper) {
                return null;
            }

            @Override
            public Integer selectCount(Wrapper<Chapter> queryWrapper) {
                return null;
            }

            @Override
            public List<Chapter> selectList(Wrapper<Chapter> queryWrapper) {
                return null;
            }

            @Override
            public List<Map<String, Object>> selectMaps(Wrapper<Chapter> queryWrapper) {
                return null;
            }

            @Override
            public List<Object> selectObjs(Wrapper<Chapter> queryWrapper) {
                return null;
            }

            @Override
            public <E extends IPage<Chapter>> E selectPage(E page, Wrapper<Chapter> queryWrapper) {
                return null;
            }

            @Override
            public <E extends IPage<Map<String, Object>>> E selectMapsPage(E page, Wrapper<Chapter> queryWrapper) {
                return null;
            }
        };
        long couresed=2;
        List<ChapterVo> chapterVos = new ArrayList<>();
        List<VideoVo> listVideo = new ArrayList<>();
        QueryWrapper<Chapter> chapterQueryWrapper = new QueryWrapper<>();
        //更据课程id获取课程里所有章节
        chapterQueryWrapper.eq("course_id", couresed);
        List<Chapter> chapters = baseMapper.selectList(chapterQueryWrapper);
        //根据id获取课程里面所有小节
        LambdaQueryWrapper<Video> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Video::getChapterId, couresed);
        List<Video> list = videoService.list(lambdaQueryWrapper);
        for (int a = 0; a < chapters.size(); a++) {
            //得到课程每个章节
            Chapter chapter = chapters.get(a);
            ChapterVo chapterVo = new ChapterVo();
            BeanUtils.copyProperties(chapter, chapterVo);
            //得到每个章节放到list集合中去
            chapterVos.add(chapterVo);
            //封装小节部分
            for (Video video : list) {
                //判断小节在那个章节里面  小节id和章节id是否相等
                if (chapter.getId().equals(video.getChapterId())) {
                    VideoVo videoVo = new VideoVo();
                    BeanUtils.copyProperties(video, videoVo);
                    listVideo.add(videoVo);
                }
            }
            //把章节里面所有小节放到相对应的章节里面
            chapterVo.setChildren(listVideo);
        }
    }
}
